package com.ruoyi.project.mtool.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.mtool.domain.Requirement;
import com.ruoyi.project.mtool.service.IRequirementService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 需求记录Controller
 * 
 * @author ruoyi
 * @date 2020-04-08
 */
@RestController
@RequestMapping("/mtool/requirement")
public class RequirementController extends BaseController
{
    @Autowired
    private IRequirementService requirementService;

    /**
     * 查询需求记录列表
     */
    @PreAuthorize("@ss.hasPermi('mtool:requirement:list')")
    @GetMapping("/list")
    public TableDataInfo list(Requirement requirement)
    {
        startPage();
        List<Requirement> list = requirementService.selectRequirementList(requirement);
        return getDataTable(list);
    }

    /**
     * 导出需求记录列表
     */
    @PreAuthorize("@ss.hasPermi('mtool:requirement:export')")
    @Log(title = "需求记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Requirement requirement)
    {
        List<Requirement> list = requirementService.selectRequirementList(requirement);
        ExcelUtil<Requirement> util = new ExcelUtil<Requirement>(Requirement.class);
        return util.exportExcel(list, "requirement");
    }

    /**
     * 获取需求记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('mtool:requirement:query')")
    @GetMapping(value = "/{requirementId}")
    public AjaxResult getInfo(@PathVariable("requirementId") Long requirementId)
    {
        return AjaxResult.success(requirementService.selectRequirementById(requirementId));
    }

    /**
     * 新增需求记录
     */
    @PreAuthorize("@ss.hasPermi('mtool:requirement:add')")
    @Log(title = "需求记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Requirement requirement)
    {
        return toAjax(requirementService.insertRequirement(requirement));
    }

    /**
     * 修改需求记录
     */
    @PreAuthorize("@ss.hasPermi('mtool:requirement:edit')")
    @Log(title = "需求记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Requirement requirement)
    {
        return toAjax(requirementService.updateRequirement(requirement));
    }

    /**
     * 删除需求记录
     */
    @PreAuthorize("@ss.hasPermi('mtool:requirement:remove')")
    @Log(title = "需求记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{requirementIds}")
    public AjaxResult remove(@PathVariable Long[] requirementIds)
    {
        return toAjax(requirementService.deleteRequirementByIds(requirementIds));
    }
}
